package com.woniu.micropropertyserver.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.microcommonsserver.entity.RenterInfoEntity;
import com.woniu.micropropertyserver.service.IRenterInfoService;
import com.woniu.micropropertyserver.util.PageRest;
import com.woniu.micropropertyserver.util.ResultMsg;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：bb
 * @date ：Created in 2021/1/26 0026
 * @description：
 * @modified By：
 * @version: $
 */

@RequestMapping("/renter")
@RestController
public class RenterController {

    @Resource
    private IRenterInfoService renterInfoServiceeImpl;


    @GetMapping(value = "/all",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg  findAll(){


       List <RenterInfoEntity> info=renterInfoServiceeImpl.findAll();
        System.out.println(info);

        return  new ResultMsg(200,"操作成功",info);
    }


    @GetMapping(value = "/findByParams",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg  findByparams(PageRest rest, RenterInfoEntity rentinfo){

        System.out.println(rentinfo);

        PageInfo info=renterInfoServiceeImpl.findAllByParams(rest, rentinfo);
        System.out.println(info);

        return  new ResultMsg(200,"操作成功",info);
    }

    @GetMapping(value = "/id",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg findById(Long id){
        System.out.println(id);
        RenterInfoEntity info = renterInfoServiceeImpl.findById(id);

        return  new ResultMsg(200,"操作成功",info);
    }

    @PutMapping(value = "/update",produces = MediaType.APPLICATION_JSON_VALUE)
    public  ResultMsg update(@RequestBody  RenterInfoEntity info){
        System.out.println(info);
        int res = renterInfoServiceeImpl.updateInfo(info);
        if(res >0){
            return  new ResultMsg(200,"操作成功",null);
        }else{
            return  new ResultMsg(200,"更新失败",null);
        }

    }
    @PutMapping(value = "/cancel",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg cancelInfo(Long id){
        int res = renterInfoServiceeImpl.delInfo(id);
        if(res >0){
            return  new ResultMsg(200,"操作成功",null);
        }else{
            return  new ResultMsg(200,"删除失败",null);
        }

    }
   @PostMapping(value = "/save",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg save(@RequestBody  RenterInfoEntity info ){
       System.out.println(info);
        Long res= renterInfoServiceeImpl.saveInfo(info);

        if(res >0){
            return  new ResultMsg(200,"操作成功",null);
        }else{
            return  new ResultMsg(200,"删除失败",null);
        }
    }



}